<template>
  <div class="main">
    <el-row>
      <el-col :span="12" :offset="6">
        <el-form :model="ruleForm" ref="ruleForm" :label-position="position">
          <el-form-item
            label="必填默认提示required|phone"
            prop="phone"
            :rules="$rules({ rule: 'required|phone' })"
          >
            <el-input v-model="ruleForm.phone"></el-input>
          </el-form-item>
          <el-form-item
            label="必填自定义提示required|num"
            prop="name"
            :rules="$rules({ rule: 'required|num', msg: '请输入数字' })"
          >
            <el-input v-model="ruleForm.name"></el-input>
          </el-form-item>
          <el-form-item
            label="正则表达式"
            prop="regexp"
            :rules="
              $rules({
                rule: 'required',
                regexp: /^[^\u4e00-\u9fa5\s]{6,10}$/,
                msg: '6-10位字符',
              })
            "
          >
            <el-input v-model="ruleForm.regexp"></el-input>
          </el-form-item>
          <el-form-item
            label="身份证"
            prop="card"
            :rules="$rules({ rule: 'required|idCard' })"
          >
            <el-input v-model="ruleForm.card"></el-input>
          </el-form-item>
          <el-form-item
            label="maxlength"
            prop="maxlength"
            :rules="$rules({ rule: 'required', maxLength: 8 })"
          >
            <el-input v-model="ruleForm.maxlength"></el-input>
          </el-form-item>
          <el-form-item
            label="介于两数之间2-6"
            prop="data"
            :rules="
              $rules({
                rule: 'required',
                min: 2,
                max: 6,
                msg: '长度为2-6个字符',
              })
            "
          >
            <el-input v-model="ruleForm.data"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit('ruleForm')"
              >提交</el-button
            >
            <el-button @click="resetForm()">取消</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>
<script>
export default {
  components: {},
  mixins: [],
  props: {},
  data() {
    return {
      position: 'right',
      ruleForm: {},
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log('succcess')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm() {
      this.$refs['ruleForm'].resetFields()
    },
  },
}
</script>
<style lang="scss" scoped>
.main {
  height: 100%;
  overflow: auto;
}
</style>
